﻿using System;
using System.Collections.Generic;

using RexToy.Xml;

namespace ScriptXCompiler
{
    public class TranslateDictionary
    {
        private Dictionary<string, string> _dict;
        public TranslateDictionary()
        {
            _dict = new Dictionary<string, string>();
        }

        public void Load(string path)
        {
            XDoc x = XDoc.LoadFromFile(path);
            var list = x.NavigateToList(@"entry");
            foreach (var entry in list)
            {
                _dict.Add(entry.GetStringValue("@cs"), entry.GetStringValue("@js"));
            }
        }

        public bool HasKey(string key)
        {
            return _dict.ContainsKey(key);
        }

        public string Translate(string csKey)
        {
            if (_dict.ContainsKey(csKey))
                return _dict[csKey];
            else
                return null;
        }
    }
}
